// instanceof 运算符用于检测构造函数的 prototype 属性是否出现在某个实例对象的原型链上。

function myInstanceof(target, origin) {
    // if (typeof target !== "object" || target === null) return false;
    if(Object(target)!==target) return false

    if (typeof origin !== "function" || !target.prototype)
        throw new TypeError("origin must be function");

    let proto = Object.getPrototypeOf(target); // 相当于 proto = target.__proto__;
    while (proto) {
        if (proto === origin.prototype) return true;
        proto = Object.getPrototypeOf(proto);
    }
    return false;
}

// console.log(Object('123')=='123')
// console.log(Object(false)==false)
// console.log(Object({})=={})

// console.log(Object.getPrototypeOf(Array));

const prototype1 = {};
const object1 = Object.create(prototype1);
console.log(Object.getPrototypeOf(object1));
console.log(Object.getPrototypeOf(object1) === prototype1);
console.log({}==={});

var proto = {};
var obj = Object.create(proto);
Object.getPrototypeOf(obj) === proto; // true

var reg = /a/;
Object.getPrototypeOf(reg) === RegExp.prototype; // true


function myinstanceof(left,right){
    if(Object(left)!==left) return false;//基本数据类型

    if(typeof right !== 'function' || !right.prototype) throw new TypeError('right must be a function')

    let _proto=Object.getPrototypeOf(left)//得到left的原型
    while(_proto){//left原型存在的话
        if(_proto==right.prototype) return true
        _proto=Object.getPrototypeOf(_proto)
    }
    return false
}
console.log(Object('123')=='123');